<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/9/10
 * Time: 19:51
 */

namespace App\CronTask;

use EasySwoole\EasySwoole\Crontab\AbstractCronTask;
use EasySwoole\MysqliPool\Mysql;
use EasySwoole\RedisPool\Redis;

/**
 * 更新联赛队伍积分
 * Class LeagueScoreCron
 * @package App\CronTask
 */
class LeagueScoreCron extends AbstractCronTask
{
    public static function getRule(): string
    {
        // TODO: Implement getRule() method.
        return '@daily';
    }
    public static function getTaskName(): string
    {
        // TODO: Implement getTaskName() method.
        // 定时任务名称
        return 'LeagueScore';
    }
    static function run(\swoole_server $server, int $taskId, int $fromWorkerId, $flags = null)
    {
        // TODO: Implement run() method.
        $db = Mysql::defer('mysql');
        $table = 'siam_lolleague';
        $league_ids = $db->getColumn($table,'league_id');
        go(function ()use($league_ids){
            Redis::invoker('redis',function (\Swoole\Coroutine\Redis $redis)use($league_ids){
                foreach ( $league_ids as $league_id ){
                    $redis->rPush('league_id',$league_id);
                }
            });
        });
    }
}